package Test_1027;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 * Dare: 2024-10-27
 * Time: 20:27
 */
public class CardDemo {
    //public static final修饰常量
    public static final String[] suits={"♣","♠","♥","♦"};
    public List<Card> buyCard(){
        List<Card> cardList= new ArrayList<>();
        for (int i = 1; i <=13 ; i++) {
            for (int j = 0; j <4 ; j++) {
                int rank=i;
                String suit=suits[j];
                Card card=new Card(suit,rank);
                cardList.add(card);
            }
        }
        return cardList;
    }
    //洗牌：
    public void shuffle(List<Card> cardList){
        Random random=new Random();
        for (int i = cardList.size()-1; i > 0 ; i--) {
            int index = random.nextInt(i);
            swap(cardList,i,index);
        }
    }
    private void swap(List<Card> cardList,int i,int j){
        Card tmp= cardList.get(i);
        cardList.set(i,cardList.get(j));
        cardList.set(j,tmp);
    }
    public List<List<Card>> play(List<Card> cardList){
        List<Card> person1=new ArrayList<>();
        List<Card> person2=new ArrayList<>();
        List<Card> person3=new ArrayList<>();
        List<List<Card>> person=new ArrayList<>();
        person.add(person1);
        person.add(person2);
        person.add(person3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card=cardList.remove(0);
                person.get(j).add(card);
            }
        }
        return person;
    }
}
